﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Enterprise.DataFactory;
using Enterprise.Infrastructure;
using Enterprise.Model.Article;
namespace Enterprise.Data.Article
{
    /// <summary>
    /// 通知公告签收数据操作
    /// </summary>
    public class ArticleRecevieData
    {

        /// <summary>
        /// 判断签收人是否签收通知公告
        /// </summary>
        /// <param name="infoId">通过公告编号</param>
        /// <param name="userId">用户编号</param>
        /// <returns></returns>
        public bool ArticleRecevieCheck(int infoId, int userId)
        {
            bool rbool = false;
            string cmd = "Select * from ARTICLE_RECEVIE where INFOID=" + infoId + "and RUSERID=" + userId;
            DataSet ds = DbExecute.GetDataSet(cmd);
            if (ds.Tables[0].Rows.Count > 0)
            {
                rbool = true;
            }
            return rbool;
        }

        /// <summary>
        ///  通知公告签收数据列表
        /// </summary>
        /// <returns></returns>
        public List<ArticleRecevieEntity> ArticleRecevieList(int infoId)
        {
            List<ArticleRecevieEntity> list = new List<ArticleRecevieEntity>();
            string cmd = "Select * from ARTICLE_RECEVIE where INFOID=" + infoId;
            IDataReader dr = DbExecute.DataReader(cmd);
            while (dr.Read())
            {
                ArticleRecevieEntity entity = new ArticleRecevieEntity();
                if (!Convert.IsDBNull(dr["RECEVIEID"])) entity.RecevieId = Convert.ToInt32(dr["RECEVIEID"]);
                if (!Convert.IsDBNull(dr["INFOID"])) entity.InfoId = Convert.ToInt32(dr["INFOID"]);
                if (!Convert.IsDBNull(dr["RUSERID"])) entity.RUserId = Convert.ToInt32(dr["RUSERID"]);
                if (!Convert.IsDBNull(dr["RDATETIME"])) entity.RDateTime = Convert.ToDateTime(dr["RDATETIME"]);
                list.Add(entity);
            }
            dr.Close();
            return list;
        }

        /// <summary>
        /// 通知公告签收数据操作方法
        /// </summary>
        /// <param name="cmd"></param>
        public void ArticleRecevieExecute(string cmd)
        {
            DbExecute.Execute(cmd);
        }
    }
}
